package pers.hl.lib_global.model.enums

enum class FileType(private val type: Int) {
    BOOK_IMG(1), BOOK_QR_CODE(2), USER_AVATAR(3), USER_QR_CODE(4);

    override fun toString(): String {
        return type.toString()
    }

    fun value(): Int {
        return type
    }

    companion object {
        fun parse(type: Int): FileType? {
            when (type) {
                1 -> return BOOK_IMG
                2 -> return BOOK_QR_CODE
                3 -> return USER_AVATAR
                4 -> return USER_QR_CODE
            }
            return null
        }

        fun value(enumType: FileType?): Int {
            return when (enumType) {
                BOOK_IMG -> 1
                BOOK_QR_CODE -> 2
                USER_AVATAR -> 3
                USER_QR_CODE -> 4
                else -> 0
            }
        }

        fun exist(type: Int?): Boolean {
            if (type == null) {
                return false
            }
            val fileType = parse(type)
            return fileType != null
        }
    }
}